#pragma once
//============================================================================
// Copyright (C) 2008-2013 Brett R. Jones 
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses 
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#include  <VxUtilLib/VxInetAddress.h>
#include "VxSktBase.h"

class VxSktUdp : public VxSktBase
{
public:
	//=== constructor ===//
	VxSktUdp();
	//=== destructor ===//
	virtual ~VxSktUdp();

	//! open a udp port
	virtual RCODE UdpOpen(	VxInetAddress& oLclIp, U16 u16Port = 54321 );			// udp port to listen on
	virtual RCODE UdpOpenMulticastListen( VxInetAddress& oLclIp, U16 u16Port, const char * pIPMulticastGroup = "239.255.255.250" );
	virtual RCODE UdpOpenUnicast( VxInetAddress& oLclIp, U16 u16Port );

	//! send data to given ip 
	virtual RCODE SendTo(	const char *	pData,			// data to send
							int				iDataLen,		// data length
							VxInetAddress&	u32RmpIp,		// destination ip
							U16				u16Port = 0 );	// port to send to ( if 0 then port specified when opened )

	//! send data to given ip 
	virtual RCODE SendTo(	const char *	pData,			// data to send
							int				iDataLen,		// data length
							const char *	pRmpIp,			// destination ip in dotted format
							U16				u16Port = 0 );	// port to send to ( if 0 then port specified when opened )

	//! send data to given ip 
	virtual RCODE sendToMulticast(	const char *	pData,			// data to send
									int				iDataLen,		// data length
									const char *	pRmpIp,			// destination ip in dotted format
									U16				u16Port = 0 );	// port to send to ( if 0 then port specified when opened )
private:

	RCODE createSocket( VxInetAddress& oLclIp, U16 u16Port, struct addrinfo ** ppoResultAddr );
	RCODE startRecieve( void );

};



